<?php
namespace App\Model\Movie;
use PhalApi\Model\DataModel;

class MovieCategory extends DataModel {

    protected function getTableName($id) {
        return 'category';
    }

    public function getList() {
        $res = $this->getORM()->select('*')->fetchAll();
        foreach ($res as $key=>$value){
            $res[$key]=array_merge($value,array('show'=>false));
        }
        return $res;
    }
    public function getCateList(){
        $res = $this->getORM()->select('*')->where(['pid'=>0])->fetchAll();
        $data[0]= ['nav'=>'首页','url'=>'/'];
        foreach ($res as $key=>$value){
            $data[$key+1]['nav']=$value['name'];
            $data[$key+1]['id']=$value['id'];
            $data[$key+1]['url']='category';
        }
        return $data;
    }
    public function getCateInfoBySourceId($id){
        $res = $this->getORM()->select('name')->where('source_id',$id)->fetchOne();
        return $res['name'];
    }
    public function getInfoByPid($pid){
        $res = $this->getORM()->select('name,source_id')->where('pid',$pid)->fetchAll();
        return $res;
    }
}